articles

Home / DeveloperSection / Articles / Custom Plugin in Joomla

Custom Plugin in Joomla

Anonymous User9634 07-Mar-2012

A plugin is a kind of Joomla extension. Plugins provide functions which are associated with trigger events. Joomla provides a set of core plugin events, but any extension can fire (custom extensions) events. When a particular event occurs, all plugin functions of the type associated with the event are executed in sequence. This is a powerful way of extending the functionality of the Joomla software. It also offers developers a way to extend the functionality of joomla content management system.

 The Plug-in Manager allows you to enable and disable Joomla plug-ins and to edit a plug-ins details and options. It is also useful for quickly enabling/disabling multiple plug-INS at once.

To open the plugin manager in joomla, first of all login in Joomla Administrator Panel backend and go to Extensions -> Plugin Manager

Custom Plugin in Joomla

Now, you will see a list of plugin which is provided by joomla by default. If you want to use these plugins, you have to select a plugin and click on ‘Enable’ button. But in any case if you want to use your own custom plugin then you have to follow the following step:

1.       Create Plugin file

2.       Upload zip file of recently created plugin file

How to create plugin file:

To create plugin file, first of all create two file first one is PHP (.php) and second one is XML file (.xml).

Here I’m creating two file with name ‘MyPlugin.php’ and ‘MyPlugin.xml’. This plugin will helped in adding site style sheet. Let’s take a look on it.

‘MyPlugin.php’ Code:
 <?php
/**
* @version   1.0
* @author    Arun Kumar Singh http://mindstick.com
* @copyright Copyright (C) 2010 MindStick Software Pvt. Ltd.
 
*/
 
// no direct access
defined('_JEXEC') or die('Restricted index access');
 
jimport('joomla.plugin.plugin');
 
class plgSystemMyPlugin extends JPlugin {
 
  public function onAfterInitialise() {
 
$app =& JFactory::getApplication();
$doc =& JFactory::getDocument();
 
if ($app->isAdmin()) {
// we are in the administrator
$doc->addStyleDeclaration( $this->params->get('admincss',''));
} else {
// we are in the frontend site     
$doc->addStyleDeclaration( $this->params->get('sitecss',''));
}
}
}

‘MyPlugin.xml’ Code:
<?xml version="1.0" encoding="utf-8"?>
<extension version="1.7.0" type="plugin" group="system" method="upgrade">
<name>System - MyPlugin</name>
<creationDate>January 28, 2012</creationDate>
<author>Arun Kumar Singh</author>
<authorUrl>http://mindstick.com</authorUrl>
<copyright>Copyright 2010 mindstick</copyright>
<license>GNU/GPL</license>
<version>2.0</version>
<description>Allows the addition of custom CSS to your site</description>
<files>
<filename plugin="MyPlugin">MyPlugin.php</filename>
</files>
<config>
<fields name="params">
<fieldset name="basic">
<field name="sitecss" type="textarea" width = "500" height ="1000"  label="Site CSS" description="The custom CSS to be added to the Site" />
 
</fieldset>
</fields>
</config>
</extension>

 Now putting these files into ‘MyPlugin’ directory and create its zip file.

Custom Plugin in Joomla

Upload plugin zip file in Joomla:

To upload zip file in joomla, first of all login in Joomla Administrator Panel and go to Extensions -> Extension Manager.

Custom Plugin in Joomla

Now browse your zip file and click on ‘Upload & Install’ button.

Custom Plugin in Joomla

Now go to Extensions -> Plugin Manager.

Custom Plugin in Joomla

Now select your uploaded plugin and click ‘Enable’ button.

Custom Plugin in Joomla

Now click on Extensions -> Plugin Manager.

Custom Plugin in Joomla

Now, click on ‘Save & Close’ button and click ‘View Site’ which is at top right in panel.

Custom Plugin in Joomla

Custom Plugin in Joomla



Updated 07-Sep-2019
I am a content writter !

Leave Comment

Comments

Liked By